package com.outsource.framework.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;

public class QueryParamerSpecial<T> implements Specification<T> {

	private Map<String, Object> map = null;
	
	public QueryParamerSpecial(Map<String, Object> map) {
		// TODO Auto-generated constructor stub
		this.map = map;
	}

	@Override
	public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query,
			CriteriaBuilder cb) {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		String province = (String)map.get("province");
		String city = (String)map.get("city");
		@SuppressWarnings("unchecked")
		List<String> level = (List<String>)map.get("level");
		String status = (String)map.get("status");
		Predicate param = cb.and(cb.equal(
				root.get("status"),status),
				root.get("level").in(level),
				cb.or(cb.equal(root.get("province"),province),cb.equal(root.get("city"),city)));
		query.where(param);
		return null;
	}

}
